﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
//using System.DirectoryServices;
using sqlserverextensions.Helper;

public partial class UserDefinedFunctions
{
    [Microsoft.SqlServer.Server.SqlFunction]
    public static SqlBoolean AD_CreateUser(string doamin, string login, string password, string fullName)
    {
        Int16 errSeverity = 16;

        //DirectoryEntry obDirEntry = null;
        try
        {
            //obDirEntry = new DirectoryEntry("WinNT://" + doamin);
            //DirectoryEntries entries = obDirEntry.Children;
            //DirectoryEntry obUser = entries.Add(login, "User");
            //obUser.Properties["FullName"].Add(fullName);
            //object obRet = obUser.Invoke("SetPassword", password);
            //obUser.CommitChanges();
        }
        catch (Exception ex)
        {
            ExceptionHelper.EvaluateException(ex, errSeverity);
            return false;
        }

        return true;
    }     
};

